﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Website.Infrastructure;

namespace Website.Tests
{
    [TestClass]
    public class DeviceDetectionTests
    {
        #region UserAgents
        private const string iPadUserAgent = 
            "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10";
        private const string iPadUserAgent2 =
            "Mozilla/5.0(iPad; U; CPU OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F191 Safari/6533.18.5";
        private const string iPadUserAgent3 =
            "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X; en-us) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3";
        private const string windowsPhoneUserAgent =
            "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; SGH-i917)";
        private string androidPhoneUserAgent =
            "Mozilla/5.0 (Linux; U; Android 2.2; en-us; DROID2 GLOBAL Build/S273) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
        private string androidTabletUserAgent =
            "Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13";
        #endregion

        [TestMethod]
        public void IsPhoneWhenWindowsPhone()
        {
            var factory = new DeviceDetectorFactory();
            var detector = factory.Create(windowsPhoneUserAgent);

            Assert.IsFalse(detector.IsTabletDevice());
            Assert.IsTrue(detector.IsPhoneDevice());
        }

        [TestMethod]
        public void IsTabletWheniPad()
        {
            var factory = new DeviceDetectorFactory();
            var detector = factory.Create(iPadUserAgent);

            Assert.IsFalse(detector.IsPhoneDevice());
            Assert.IsTrue(detector.IsTabletDevice());
        }

        [TestMethod]
        public void IsPhoneWhenAndroidPhone()
        {
            var factory = new DeviceDetectorFactory();
            var detector = factory.Create(androidPhoneUserAgent);

            Assert.AreEqual(detector.GetType(), typeof(AndroidDeviceDetector));
            Assert.IsTrue(detector.IsPhoneDevice());
            Assert.IsFalse(detector.IsTabletDevice());
        }

        [TestMethod]
        public void IsTabletWhenAndroidTablet()
        {
            var factory = new DeviceDetectorFactory();
            var detector = factory.Create(androidTabletUserAgent);

            Assert.AreEqual(detector.GetType(), typeof(AndroidDeviceDetector));
            Assert.IsFalse(detector.IsPhoneDevice());
            Assert.IsTrue(detector.IsTabletDevice());
        }

        [TestMethod]
        public void IsTabletWhenKindleFireHd()
        {
        }

        [TestMethod]
        public void IsTabletWhenNexus7()
        {
        }
    }
}
